import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:buy_flutter/net/bean/UserInfoBean.dart';
import 'package:buy_flutter/net/bean/UserLoginBean.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';

part 'main_event.dart';

part 'main_state.dart';

class MainBloc extends Bloc<MainEvent, MainState> {
  MainBloc() : super(MainInitial());

  @override
  Stream<MainState> mapEventToState(MainEvent event) async* {
    if (event is BottomNavigationChanged) {
      yield _mapBottomNavigationChangedToState(event, state);
    } else if (event is MainUnitViewChanged) {
      yield _mapUnitViewChangedToState(event, state);
    } else if (event is MainUserInfoChanged) {
      yield _mapMainUserInfoChangedToState(event, state);
    }
  }

  MainState _mapBottomNavigationChangedToState(
      BottomNavigationChanged event, MainState state) {
    return MainState(index: event.index);
  }

  MainState _mapUnitViewChangedToState(
      MainUnitViewChanged event, MainState state) {
    return MainState(unitLists: event.unitViews);
  }

  MainState _mapMainUserInfoChangedToState(
      MainUserInfoChanged event, MainState state) {
    return MainState(userInfoBean: event.userInfoBean);
  }
}
